//
//  PMCollision.h
//  PezMonkey
//
//  Created by Spence DiNicolantonio on 11/9/09.
//  Copyright 2009 Necrosoft. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "PMCore.h"

@class PMSpace, PMShape;


#pragma mark Enums / Types

// Collision states
typedef enum _PMCollisionState {
	PMCollisionStateBegan,
	PMCollisionStatePreSolve,
	PMCollisionStatePostSolve,
	PMCollisionStateEnded,
	PMCollisionStateUndefined
} PMCollisionState;

// Contact type definition
typedef struct _PMContact {
	PMVect point;
	PMVect normal;
	PMFloat distance;
} PMContact;

#pragma mark -


@interface PMCollision : NSObject {
@private
	// The space in which the collision occured
	PMSpace *space;
	
	// Collision shapes involved in the collision
	PMShape *shapeA;
	PMShape *shapeB;
	
	// Number of contacts in the collision
	NSUInteger contactCount;
	PMContact *contacts;
	
	// State of the collision
	PMCollisionState state;
}

@property (nonatomic, retain, readonly) PMSpace *space;
@property (nonatomic, retain, readonly) PMShape *shapeA;
@property (nonatomic, retain, readonly) PMShape *shapeB;
@property (readonly) NSUInteger contactCount;
@property (nonatomic, readonly) PMContact *contacts;
@property (readonly) PMCollisionState state;


#pragma mark -
#pragma mark Init
- (id)initWithSpace:(PMSpace *)theSpace arbiter:(cpArbiter *)arbiter state:(PMCollisionState)collisionState;

#pragma mark Convenience
+ (PMCollision *)collisionWithSpace:(PMSpace *)theSpace arbiter:(cpArbiter *)arbiter state:(PMCollisionState)collisionState;


#pragma mark -
#pragma mark Getters
- (PMContact)contact:(NSUInteger)contactIndex;
- (PMVect)positionOfContact:(NSUInteger)contactIndex;
- (PMVect)normalOfContact:(NSUInteger)contactIndex;
- (PMFloat)distanceOfContact:(NSUInteger)contactIndex;

@end
